package com.ruoyi.charge.clinet;

import com.ruoyi.charge.manager.ChargingPileManager;
import io.vertx.core.AbstractVerticle;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.Solon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 充电桩Verticle，每个充电桩对应一个独立实例
 */
@AllArgsConstructor
public class ChargingPileVerticle extends AbstractVerticle {
    private static final Logger logger = LoggerFactory.getLogger(ChargingPileVerticle.class);
    private final String sn;
    private final String host;
    private final int port;
    private ChargingPileManager chargingPileManager;

    public ChargingPileVerticle(String sn, String host, int port) {
        this.port = port;
        this.host = host;
        this.sn = sn;
        chargingPileManager = Solon.context().getBean(ChargingPileManager.class);
    }

    @Override
    public void start() {
        logger.info("初始化充电桩[{}]", sn);
        chargingPileManager.registerChargingPile(sn, host, port);
    }


    @Override
    public void stop() {
        logger.info("注销充电桩[{}]", sn);
        chargingPileManager.unregisterChargingPile(sn);
    }
}
